function Tests = modelForecast()
Tests = functiontests(localfunctions);
end
%#ok<*DEFNU>


%**************************************************************************


function setupOnce(This)
m = model('testForecast.model','linear=',true);
m = solve(m);
m = sstate(m);
This.TestData.model = m;
end % setupOnce( )


%**************************************************************************


function testJForecast(This)
m = This.TestData.model;
xNames = get(m,'xNames');

T = 10;
Ti = 4;
Te = 3;
d = sstatedb(m,1:T);

for ant = [true,false]
    C = struct();
    C.i = tseries(1:Ti,1.2);
    
    f0 = jforecast(m,d,1:T,C,'meanOnly=',true,'anticipate=',ant);
    s0 = simulate(m,f0,1:T,'anticipate=',ant);
    for i = 1 : length(xNames)
        name = xNames{i};
        assertEqual(This,f0.(name)(1:T),s0.(name)(1:T),'AbsTol',1e-14);
    end
    assertEqual(This,C.i(1:Ti),f0.i(1:Ti),'AbsTol',1e-14);
    
    d.eps_y(1:Te) = -0.2;
    f1 = jforecast(m,d,1:T,C,'meanOnly=',true,'anticipate=',ant);
    s1 = simulate(m,f1,1:T,'anticipate=',ant);
    for i = 1 : length(xNames)
        name = xNames{i};
        assertEqual(This,f1.(name)(1:T),s1.(name)(1:T),'AbsTol',1e-14);
    end
    assertEqual(This,C.i(1:Ti),f0.i(1:Ti),'AbsTol',1e-14);
    
    p = plan(m,1:T);
    p = condition(p,'i',1:Ti);
    d.i(1:Ti) = 1.2;
    f2 = jforecast(m,d,1:T,'meanOnly=',true,'plan=',p,'anticipate=',ant);
    s2 = simulate(m,f2,1:T,'anticipate=',ant);
    for i = 1 : length(xNames)
        name = xNames{i};
        assertEqual(This,f2.(name)(1:T),s2.(name)(1:T),'AbsTol',1e-14);
    end
    assertEqual(This,d.i(1:Ti),f0.i(1:Ti),'AbsTol',1e-14);
end

end % testJForecast()
